<?php
    $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

    define("TIREPRICE", 100);
    define("OILPRICE", 10);
    define("SPARKPRICE", 4);

    $taxrate = 0.10;
    $totalqty = 0;
    $totalamount = 0.00;

    $tireqty = $_POST['tireqty'];
    $oilqty = $_POST['oilqty'];
    $sparkqty = $_POST['sparkqty'];
    $address = $_POST['address'];
    $date = date("H:i:s jS F Y");

    $totalqty = $tireqty + $oilqty + $sparkqty;
    $totalamount = number_format($tireqty*TIREPRICE
                                + $oilqty*OILPRICE
                                + $sparkqty*SPARKPRICE, 2);
    $totalamount = number_format($totalamount*(1+$taxrate), 2);

    $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
        .$sparkqty." spark plugs\t\$".$totalamount."\t".$address."\n";

    $fp = fopen('./orders.txt', 'ab');
    flock($fp, LOCK_EX);
    if (!$fp) {
        echo "Your order can not be processed now!<br />";
        exit();
    }
    fwrite($fp, $outputstring, strlen($outputstring));
    flock($fp, LOCK_UN);
    fclose($fp);
    echo "<p>order written.</p>";
?>
